lib/static-delta: document and check parameters format
authorLuca BRUNO <luca.bruno@coreos.com>
Tue, 11 Oct 2022 08:50:10 +0000 (08:50 +0000)
committerLuca BRUNO <luca.bruno@coreos.com>
Thu, 13 Oct 2022 16:29:59 +0000 (16:29 +0000)
This enhances the logic handling GVariant parameters within
`ostree_repo_static_delta_generate()`.
Several of those entries are expected to be zero-terminated values,
and this implicit assumption has been observed to be an hidden trap
in languages where strings and arrays may not carry a terminator value
(e.g. Rust).
In order to improve the situation, this makes the documentation more
explicit and actively tries to catch invalid input parameters.

src/libostree/ostree-repo-static-delta-compilation.c

index 28b421395d0c4b3cb3de77fbd2aab2303f1f4f26..dece876ee23e04659c73a9a71f0e49ab1230119a 100644 (file)
@@ -1334,9 +1334,9 @@ get_fallback_headers (OstreeRepo               *self,
  *   - inline-parts: b: Put part data in header, to get a single file delta.  Default FALSE.
  *   - verbose: b: Print diagnostic messages.  Default FALSE.
  *   - endianness: b: Deltas use host byte order by default; this option allows choosing (G_BIG_ENDIAN or G_LITTLE_ENDIAN)
- *   - filename: ay: Save delta superblock to this filename, and parts in the same directory.  Default saves to repository.
- *   - sign-name: ay: Signature type to use.
- *   - sign-key-ids: as: Array of keys used to sign delta superblock.
+ *   - filename: ^ay: Save delta superblock to this filename (bytestring), and parts in the same directory.  Default saves to repository.
+ *   - sign-name: ^ay: Signature type to use (bytestring).
+ *   - sign-key-ids: ^as: NULL-terminated array of keys used to sign delta superblock.
  */
 gboolean
 ostree_repo_static_delta_generate (OstreeRepo                   *self,
@@ -1409,9 +1409,13 @@ ostree_repo_static_delta_generate (OstreeRepo                   *self,
 
   if (!g_variant_lookup (params, "filename", "^&ay", &opt_filename))
     opt_filename = NULL;
+  else if (opt_filename[0] == '\0')
+    return glnx_throw (error, "Invalid 'filename' parameter");
 
   if (!g_variant_lookup (params, "sign-name", "^&ay", &opt_sign_name))
     opt_sign_name = NULL;
+  else if (opt_sign_name[0] == '\0')
+    return glnx_throw (error, "Invalid 'sign-name' parameter");
 
   if (!g_variant_lookup (params, "sign-key-ids", "^a&s", &opt_key_ids))
     opt_key_ids = NULL;